package com.kinggm.demo.controller;

import com.sankuai.inf.leaf.common.Result;
import com.sankuai.inf.leaf.common.Status;
import com.sankuai.inf.leaf.service.SnowflakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/leaf")
public class LeafController {
    //雪花算法ID
    @Resource
    private SnowflakeService snowflakeService;

    @RequestMapping("/snowflake")
    public String getSnowflakeId() {

        //获取snowflake分布式ID
        //id  这个参数是没有意义的，只是为了和号段模式的接口统一，所以要传一个参数，自己随意定义一个
        Result r = snowflakeService.getId("id");

        //判断是否成功，成功返回具体的id，不成功返回错误提示
        if (r.getStatus() == Status.SUCCESS) {
            return String.valueOf(r.getId());
        }else {
            return "失败";
        }
    }


}
